<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.yc.comm.Constant"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/ext-all.css">  
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/edit-grid.css">   
	<script type="text/javascript" src="<%=path%>/js/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/DWRTreeLoader.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/SearchField.js"></script> 
	<script type="text/javascript" src="<%=path%>/js/ext/query-dwr-proxy.js"></script>	
	<script type='text/javascript' src="<%=path%>/dwr/engine.js"></script>
	<script type='text/javascript' src="<%=path%>/dwr/util.js"></script> 
	<script type='text/javascript' src="<%=path%>/dwr/interface/JImport.js"></script>
    <title>基站数据批量导入</title>  

  </head>
  
<body>
<form id="backForm" method="POST" action="<%=path%>/pages/query/query.jsp">
	<input type="hidden" name="choosedTableId" id="choosedTableId_ID" value=""/>
	<input type="hidden" name="choosedBtsName" id="choosedBtsName_ID" value=""/>
</form>
<div id="uploadDIV" /></div>
<div id="mainTabPanelDIV" style="width:100%;height:100%"></div>
<script>

var BTSDS
Ext.onReady(function(){  
	Ext.QuickTips.init();
	
	   var viewport = new Ext.Viewport({
	    layout:'border',
	    frame:true,
	    items:[ 
		{
		        region: 'north',
		        contentEl: 'uploadDIV',
		        margins:'110 5 5 5',
		        split: false,
		        //border: true,
		        collapsible: false,
		        height: 80
		    },
		{
		        region: 'center',
		        contentEl: 'mainTabPanelDIV',
		        margins:'5 5 30 5',
		        split: true,
		        border: true	
		    }]
		});
		
	var upForm = new Ext.form.FormPanel({ 
			renderTo : 'uploadDIV',
			bodyStyle : 'padding:5px 5px 0',
			frame : true,
			id: 'FormUpload',
			labelAlign: 'right', 
			labelWidth:100,
			url: '<%=path%>/ImportDataUploadServlet',
			fileUpload: true, 
			items: [
					{
						xtype: 'textfield',    
						fieldLabel: '文件名',    
						name: 'file',    
						width:300 ,
						inputType: 'file',//文件类型  
						allowBlank:false,
						blankText :'请选择上传的文件'	
					}],
			buttons:[
				{
					text: '上传',
					handler:function()
					{ 
						var _form = upForm.getForm();	
						if (_form.isValid()) 
						{	
							_form.submit(
							{  
								success:function(_form, action){
									//Ext.Msg.alert('成功', action.result.msg); 									
								},  
								failure:function(_form, action){  
									//Ext.Msg.alert('错误', action.result.msg);  
								},
								waitMsg:'正在上传数据，稍后...'
							});
						}					
					}
				}
			]		
				
		})
	
	
	var BTSType = Ext.data.Record.create([								
							   {name: 'id', type: "string"},
							   {name: 'fileName', type: "string"}
						 ]); 
	var BTSCM = new Ext.grid.ColumnModel(
			[	             
				{header: "文件名", sortable: true,width:400, dataIndex: 'fileName',align:'left'}, 
				{header: "导入",  sortable: true, dataIndex: 'fileName',align:'left',renderer: showImport},	
				{header: "删除",  sortable: true, dataIndex: 'fileName',align:'left',renderer: showDelete}	
			]
		);
	function showImport(value)
	{ 
		return "<input type='button' value='导入' class='x-btn button' onclick='doDeleteImport(\"" + value  +   "\")'>";  
	}	
	
	function showDelete(value)
	{ 
		return "<input type='button' value='删除' class='x-btn button' onclick='doDeleteSectionOutInfo(\"" + value  +   "\")'>";  
	}	
	BTSDS = new Ext.data.Store({
				proxy: new Ext.data.DWRProxy(JImport.getAllFiles, true),	
				reader: new Ext.data.ListRangeReader({
					totalProperty: 'totalSize',
					id: 'id'
				}, BTSType),
				sortInfo:{field:'id', direction:'ASC'} 
			});		
	var towerMountedGridDiv = Ext.get("mainTabPanelDIV");
	
	var BTSGrid = new Ext.grid.GridPanel({	
			el:'mainTabPanelDIV',
			ds: BTSDS,
			cm: BTSCM,  
			autoWidth : true,  
			autoScroll : true,  
			autoHeight: false,
			region : 'center',
			height: towerMountedGridDiv.getComputedHeight(), 
			minSize: 200,		
			frame:true,
			collapsible:false, 
			enableDragDrop:false,  
			
			bbar: new Ext.PagingToolbar({
					pageSize: 17,
					store: BTSDS,
					displayInfo: true,
					displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
					emptyMsg: "没有记录"
				})
		});		
	
	BTSDS.load();	
	BTSGrid.render();	
});	


function doDeleteImport(fileName){
	Ext.MessageBox.confirm('确认导入', '该操作将覆盖以前数据，是否要导入该数据?', 
		function(btn) {
			if(btn == 'yes') // 选中了是按钮	
			{	
				JImport.importDataToBase(fileName, function(data) {
				if(data) {							    	     		
					Ext.Msg.alert("成功","数据导入成功!");
					BTSDS.load();	
				 }else 
				 {
					Ext.Msg.alert("失败","数据导入失败!");
				 }
				 }); 
				 BTSDS.load();	
				
			}
		}
	);
}

function doDeleteSectionOutInfo(fileName)
{
	Ext.MessageBox.confirm('确认删除', '确认删除该数据信息?', 
		function(btn) {
		 if(btn == 'yes') // 选中了是按钮	
		 {	
			JImport.deleteFile(fileName, function(data) {
				if(data) {							    	     		
					Ext.Msg.alert("成功","删除成功!");
				 }else 
				 {
					Ext.Msg.alert("失败","删除失败!");
				 }
				 });  
			
		 }
		}
	);
}


</script>
</body>
</html>
